package com.whfp.coky.ble

import android.bluetooth.BluetoothGatt
import com.clj.fastble.callback.BleGattCallback
import com.clj.fastble.data.BleDevice
import com.clj.fastble.exception.BleException
import com.whfp.coky.ui.base.BaseActivity

/**
 *
 * 重写blesdk中的连接回调
 * created by coky on 2022/3/28
 */
abstract class ConnCallback(val actvity:BaseActivity<*,*>): BleGattCallback() {

    override fun onStartConnect() {
        actvity.showDialog("连接中..")
    }

    override fun onConnectFail(bleDev: BleDevice?, bleExc: BleException?) {
        actvity.hideDialog()
        connFailed(bleDev,bleExc)
    }

    override fun onConnectSuccess(bleDev: BleDevice?, btGatt: BluetoothGatt?, i: Int) {
        actvity.hideDialog()
        connSuccess(bleDev,btGatt,i)
    }

    override fun onDisConnected(isActive: Boolean, bleDev: BleDevice?, btGatt: BluetoothGatt?, i: Int) {
        actvity.hideDialog()
        disConned(isActive,bleDev,btGatt,i)
    }



    abstract fun connFailed(bleDev: BleDevice?, bleExc: BleException?)
    abstract fun connSuccess(bleDev: BleDevice?, btGatt: BluetoothGatt?, i: Int)
    abstract fun disConned(isActive: Boolean, bleDev: BleDevice?, btGatt: BluetoothGatt?, i: Int)

}